feat: Add DistributedOptimizer and support ZeRO-1 #98
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
通过
--use_distributed_optimizer来开启基于分布式优化器的 ZeRO-1 优化。Stage 1 的优化对 SGD 没有效果,但是依然在 GPT-2 训练脚本中加了相关 option,为的是之后 stage 2/3 的扩展。实现细节:
--use_distributed_optimizer时则走原先的逻辑;models->Parameters()的构造 function 方法,DistributedOptimizer 在构造时会接受这个 function,并在其构造函数内部创建 base_optimizer;详细实现流程可以参考叙述:https://gxtctab8no8.feishu.cn/wiki/XQbGwXSsZi3MutkZuhXcKWsinnY#share-QU0fdM1cYoT06vxmwMbcnLJUn1b
两个比较重要的细节: